﻿Imports System.ComponentModel
Imports Autodesk.AutoCAD.DatabaseServices
<RefreshProperties(System.ComponentModel.RefreshProperties.All), _
TypeConverter(GetType(OrderedPropertyGrid.PropertySorter)), _
DefaultPropertyAttribute("Segregation")> _
Public Class CLDS_Segment_Properties
    Private _Obj As ObjectId
    Private _Tag As String = "-"
    Private _ID As String = "-"
    Private _FNode As String
    Private _TNode As String
    Private _Area As String
    Private _Segregation As String
    Private _Comment As String
    Private _Type As String
    Private _Status As String = "-"
    Private _Length As Double
    Private _Raceway As String = "-"
    Private _Elevation As String = "-"
    Private _MTCount As Integer = 0
    Private _Major As String = "N"

    Private v_varies As String = "*VARIES*"                     ' Denotes conflicting values in multiple object selection

    Public Sub SetAttributes()
        Dim pdID As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("ID")
        Dim brID As ReadOnlyAttribute = DirectCast(pdID.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiID As System.Reflection.FieldInfo = brID.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiID.SetValue(brID, (_Tag = v_varies Or (_Tag = "SEG" And Left$(_ID, 1) <> "-") Or (_Tag = "PS" And Left$(_ID, 1) <> "-") Or _Tag = "JUMP" Or _Tag = "OFFROUTE" Or _Tag = "NODE" Or _Tag = "DEVICE"))
        Dim pdFN As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("FNode")
        Dim brFN As ReadOnlyAttribute = DirectCast(pdFN.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiFN As System.Reflection.FieldInfo = brFN.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiFN.SetValue(brFN, (_Tag = v_varies Or _Tag = "SEG" Or _Tag = "PS" Or _Tag = "JUMP" Or _Tag = "OFFROUTE" Or _Tag = "NODE" Or _Tag = "DEVICE"))
        Dim pdTN As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("TNode")
        Dim brTN As ReadOnlyAttribute = DirectCast(pdTN.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiTN As System.Reflection.FieldInfo = brTN.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiTN.SetValue(brTN, (_Tag = v_varies Or _Tag = "SEG" Or _Tag = "PS" Or _Tag = "JUMP" Or _Tag = "OFFROUTE" Or _Tag = "NODE" Or _Tag = "DEVICE"))
        Dim pdAR As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("Area")
        Dim brAR As ReadOnlyAttribute = DirectCast(pdAR.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiAR As System.Reflection.FieldInfo = brAR.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiAR.SetValue(brAR, (_Tag = v_varies Or _Tag = "SEG" Or _Tag = "JUMP" Or _Tag = "OFFROUTE"))
        Dim pdSG As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("Segregation")
        Dim brSG As ReadOnlyAttribute = DirectCast(pdSG.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiSG As System.Reflection.FieldInfo = brSG.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiSG.SetValue(brSG, (_Tag = v_varies Or _Tag = "JUMP" Or _Tag = "OFFROUTE" Or _Tag = "NODE" Or _Tag = "DEVICE"))
        Dim pdCM As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("Comment")
        Dim brCM As ReadOnlyAttribute = DirectCast(pdCM.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiCM As System.Reflection.FieldInfo = brCM.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiCM.SetValue(brCM, (_Tag = v_varies Or _Tag = "JUMP" Or _Tag = "OFFROUTE" Or _Tag = "SEG"))
        Dim pdTY As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("Type")
        Dim brTY As ReadOnlyAttribute = DirectCast(pdTY.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiTY As System.Reflection.FieldInfo = brTY.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiTY.SetValue(brTY, (_Tag = v_varies Or _Tag = "JUMP" Or _Tag = "OFFROUTE" Or _Tag = "NODE" Or _Tag = "DEVICE"))
        Dim pdLN As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("Length")
        Dim brLN As ReadOnlyAttribute = DirectCast(pdLN.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiLN As System.Reflection.FieldInfo = brLN.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiLN.SetValue(brLN, (_Tag = v_varies Or _Tag = "PS" Or _Tag = "OFFROUTE" Or _Tag = "NODE" Or _Tag = "DEVICE"))
        'fiLN.SetValue(brLN, (_Tag = v_varies Or _Tag = "SEG" Or _Tag = "PS" Or _Tag = "JUMP" Or _Tag = "OFFROUTE" Or _Tag = "NODE" Or _Tag = "DEVICE"))
        Dim pdRW As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("Raceway")
        Dim brRW As ReadOnlyAttribute = DirectCast(pdRW.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiRW As System.Reflection.FieldInfo = brRW.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiRW.SetValue(brRW, (_Tag = v_varies Or _Tag = "OFFROUTE" Or _Tag = "NODE" Or _Tag = "DEVICE"))
        Dim pdEL As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("Elevation")
        Dim brEL As ReadOnlyAttribute = DirectCast(pdEL.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiEL As System.Reflection.FieldInfo = brEL.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiEL.SetValue(brEL, (_Tag = v_varies Or _Tag = "OFFROUTE" Or _Tag = "SEG" Or _Tag = "JUMP"))
        Dim pdMJ As PropertyDescriptor = TypeDescriptor.GetProperties(Me.GetType()).Item("Major")
        Dim brMJ As ReadOnlyAttribute = DirectCast(pdMJ.Attributes.Item(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
        Dim fiMJ As System.Reflection.FieldInfo = brMJ.GetType().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        fiMJ.SetValue(brMJ, (_Tag <> "PS" And _Tag <> "NODE"))
    End Sub
    <CategoryAttribute("Obj"), _
      Browsable(False), _
      [ReadOnly](True), _
      BindableAttribute(False), _
      DefaultValueAttribute(""), _
    OrderedPropertyGrid.PropertyOrder(1), _
    DisplayName("Object ID"), _
      DesignOnly(False), _
      DescriptionAttribute("Object ID")> _
      Public Property Obj() As ObjectId
        Get
            Return _Obj
        End Get
        Set(ByVal value As ObjectId)
            _Obj = value
        End Set
    End Property
    <CategoryAttribute("Segment"), _
      Browsable(True), _
      [ReadOnly](True), _
      BindableAttribute(False), _
      DefaultValueAttribute(""), _
    OrderedPropertyGrid.PropertyOrder(1), _
    DisplayName("Entity type"), _
      DesignOnly(False), _
      DescriptionAttribute("Entity type")> _
      Public Property Tag() As String
        Get
            Return UCase(_Tag)
        End Get
        Set(ByVal Value As String)
            _Tag = UCase(Value)
        End Set
    End Property
    <CategoryAttribute("Segment"), _
        Browsable(True), _
        [ReadOnly](True), _
        BindableAttribute(False), _
        DefaultValueAttribute(""), _
        DesignOnly(False), _
        OrderedPropertyGrid.PropertyOrder(2), _
        DisplayName("ID"), _
        DescriptionAttribute("Unique ID")> _
        Public Property ID() As String
        Get
            Return UCase(_ID)
        End Get
        Set(ByVal Value As String)
            _ID = UCase(Value)
        End Set
    End Property
    <CategoryAttribute("Segment"), _
       Browsable(True), _
       [ReadOnly](True), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(3), _
       DisplayName("From node"), _
       DescriptionAttribute("Segment from node")> _
       Public Property FNode() As String
        Get
            Return UCase(_FNode)
        End Get
        Set(ByVal Value As String)
            _FNode = UCase(Value)
        End Set
    End Property
    <CategoryAttribute("Segment"), _
       Browsable(True), _
       [ReadOnly](True), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(4), _
       DisplayName("To node"), _
       DescriptionAttribute("Segment to node")> _
       Public Property TNode() As String
        Get
            Return UCase(_TNode)
        End Get
        Set(ByVal Value As String)
            _TNode = UCase(Value)
        End Set
    End Property
    <TypeConverter(GetType(CLDS_Area_Prop_Converter)), _
    CategoryAttribute("Node"), _
       Browsable(True), _
       [ReadOnly](False), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(5), _
       DisplayName("Area"), _
       DescriptionAttribute("Area code")> _
       Public Property Area() As String
        Get
            Return UCase(_Area)
        End Get
        Set(ByVal Value As String)
            _Area = UCase(Value)
        End Set
    End Property
    <TypeConverter(GetType(CLDS_YN_Prop_Converter)), _
    CategoryAttribute("Node"), _
       Browsable(True), _
       [ReadOnly](False), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(5), _
       DisplayName("Major"), _
       DescriptionAttribute("Node is a major node")> _
       Public Property Major() As String
        Get
            Return _Major
        End Get
        Set(ByVal Value As String)
            _Major = Value
        End Set
    End Property
    <TypeConverter(GetType(CLDS_Seg_Prop_Converter)), _
    CategoryAttribute("Segment"), _
       Browsable(True), _
       [ReadOnly](False), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(6), _
       DisplayName("Segregation"), _
       DescriptionAttribute("Single, group or multi-tier segregation code")> _
       Public Property Segregation() As String
        Get
            Return UCase(_Segregation)
        End Get
        Set(ByVal Value As String)
            _Segregation = UCase(Value)
        End Set
    End Property
    <TypeConverter(GetType(CLDS_Type_Prop_Converter)), _
    CategoryAttribute("Segment"), _
       Browsable(True), _
       [ReadOnly](False), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(7), _
       DisplayName("Type"), _
       DescriptionAttribute("Simple or multi-tier network equipment code")> _
       Public Property Type() As String
        Get
            Return UCase(_Type)
        End Get
        Set(ByVal Value As String)
            _Type = UCase(Value)
        End Set
    End Property
    <CategoryAttribute("Segment"), _
       Browsable(True), _
       [ReadOnly](True), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(8), _
       DisplayName("Length [m]"), _
       DescriptionAttribute("Length of segment")> _
       Public Property Length() As Double
        Get
            Return _Length
        End Get
        Set(ByVal Value As Double)
            _Length = Value
        End Set
    End Property
    <CategoryAttribute("Segment"), _
       Browsable(True), _
       [ReadOnly](True), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(9), _
       DisplayName("Raceway ID"), _
       DescriptionAttribute("Segment Raceway ID")> _
       Public Property Raceway() As String
        Get
            Return UCase(_Raceway)
        End Get
        Set(ByVal Value As String)
            _Raceway = UCase(Value)
        End Set
    End Property
    <CategoryAttribute("Segment"), _
       Browsable(True), _
       [ReadOnly](True), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(10), _
       DisplayName("Elevation"), _
       DescriptionAttribute("Elevation")> _
       Public Property Elevation() As String
        Get
            Return UCase(_Elevation)
        End Get
        Set(ByVal Value As String)
            _Elevation = UCase(Value)
        End Set
    End Property
    <CategoryAttribute("Comment"), _
       Browsable(True), _
       [ReadOnly](True), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(11), _
       DisplayName("Comment"), _
       DescriptionAttribute("Comment")> _
       Public Property Comment() As String
        Get
            Return _Comment
        End Get
        Set(ByVal Value As String)
            _Comment = Value
        End Set
    End Property
    <CategoryAttribute("Multi-tier"), _
       Browsable(True), _
       [ReadOnly](True), _
       BindableAttribute(False), _
       DefaultValueAttribute(""), _
       DesignOnly(False), _
       OrderedPropertyGrid.PropertyOrder(12), _
       DisplayName("Tier count"), _
       DescriptionAttribute("Number of tiers in multi-tier layout, or zero if not multi-tier")> _
       Public Property MTCount() As Integer
        Get
            Return _MTCount
        End Get
        Set(ByVal Value As Integer)
            _MTCount = Value
        End Set
    End Property
End Class
